﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Linq;
namespace Exact_Extension
{
    public partial class MsgSpecialCase : DevExpress.XtraEditors.XtraForm
    {
        ExactDataContext DS;
        ISHCMC_Invoice Inv;
        Common common;
        IFormatProvider culture = new System.Globalization.CultureInfo("fr-FR", true);
        public MsgSpecialCase(ExactDataContext _DS,ISHCMC_Invoice _Inv)
        {
            InitializeComponent();
            DS = _DS;
            Inv = _Inv;
            common = new Common(_DS);
            this.dateEdit_Start.EditValue = DateTime.Now.Date;
            this.dateEdit_End.EditValue = DateTime.Now.Date;
        }

        private void btnAgree_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.radioGroup1.SelectedIndex == 0)
                {
                    common.ProcessTrackingInvoice(Inv, "Assign Special Discount with Fix Amount " + this.txtAmount.Text, "Set Special Discount");
                    ISHCMC_Invoice InvUpdate = DS.ISHCMC_Invoices.Single(c => c.ID == Inv.ID);
                    InvUpdate.Amount = Convert.ToDecimal(this.txtAmount.Text);
                    InvUpdate.SpecialDiscount = true;
                    InvUpdate.SpecialAmount = true;
                    InvUpdate.SPD_StartDate = Convert.ToDateTime(this.dateEdit_Start.EditValue, culture);
                    InvUpdate.SPD_EndDate = Convert.ToDateTime(this.dateEdit_End.EditValue, culture);

                    DS.SubmitChanges();

                }
                else
                {

                    common.ProcessTrackingInvoice(Inv, "Assign Special Discount with Percentage Discount " + this.txtAmount.Text, "Set Special Discount");
                    ISHCMC_Invoice InvUpdate = DS.ISHCMC_Invoices.Single(c => c.ID == Inv.ID);
                    InvUpdate.Discount = Convert.ToDecimal(this.txtAmount.Text);
                    InvUpdate.SpecialDiscount = true;
                    InvUpdate.SpecialPercent = true;
                    InvUpdate.SPD_StartDate = Convert.ToDateTime(this.dateEdit_Start.EditValue, culture);
                    InvUpdate.SPD_EndDate = Convert.ToDateTime(this.dateEdit_End.EditValue, culture);
                    DS.SubmitChanges();
                }
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                this.DialogResult = DialogResult.No;
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }


    }
}